#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#define DEBUG 1
#define DBG(n) if (DEBUG){ n }
#define ss(s) scanf("%s", s)
#define si(i) scanf("%d",&i)
#define FORN(i,n) for (int i=0;i<n;i++)
#define op1(arr, n) DBG(for (int i=0;i<n;i++) cout << arr[i] << endl; cout << endl; )
#define op2(arr, arr2, n) DBG(for (int i=0;i<n;i++) cout << arr[arr2[i]] << endl; cout << endl; )
#define MAXN 505
#define MAXM 100005
using namespace std;

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;

ll substr_count(int n, char *s){
    DBG( cout << s << endl; )
    VI cnt(128);
    for (int i=0;i<n;i++) cnt[s[i]]++;
    for (int i=1;i<128;i++) cnt[i] += cnt[i-1];
    VI p(n);
    for (int i=0;i<n;i++) p[--cnt[s[i]]] = i;
    op1(p, n)

    VVI c(1, VI(n));
    int w = 0;
    for (int i=0;i<n;i++){
        if (i == 0 || s[p[i]] != s[p[i-1]]) w++;
        c[0][p[i]] = w-1;
    }
    DBG(FORN(i,n) cout << p[i] << " " <<  c[0][p[i]] << endl;)
    for (int k=0, h=1; h<n; k++, h<<=1){
        VI pn(n);
        for (int i=0;i<n;i++){
            pn[i] = p[i] - h;
            if (pn[i] < 0) pn[i] += n;
        }
        VI cnt(w, 0);
        for (int i=0;i<n;i++) cnt[c[k][pn[i]]]++;
        for (int i=1;i<w;i++) cnt[i] += cnt[i-1];
        for (int i=n;i--;)
            p[--cnt[c[k][pn[i]]]] = pn[i];

        DBG(FORN(i,n) cout << p[i] << " " <<  " " << pn[i] << " " << c[k][pn[i]] << endl; cout << endl; )
        w = 0;
        c.push_back(VI(n));
        for (int i=0;i<n;i++){
            if (i == 0 || c[k][p[i]] != c[k][p[i-1]]) w++;
            else {
                int i1 = p[i]   + h; if (i1 >= n) i1 -= n;
                int i2 = p[i-1] + h; if (i2 >= n) i2 -= n;
                if (c[k][i1] != c[k][i2]) w++;
            }
            c[k+1][p[i]] = w-1;
        }
    }
    return 0;
}

char s[200003];

int main()
{
    freopen("TASTR.txt","r", stdin);
    ss(s);
    int n = strlen(s) + 1;
    s[n-1] = 'a' - 1;
    s[n] = 0;
    ll ans = substr_count(n, s);
/*
    ss(s+n);
    int m = strlen(s+n)+1;
    s[n+m-1] = 'a' - 2;
    s[n+m] = 0;

    ll ans1 = substr_count(n, s);
    ll ans2 = substr_count(m, s+n);
    ll ans3 = substr_count(n+m, s) - ll(n) * m;
    ll ans  = 2*ans3 - ans1 - ans2;
*/
    printf("%lld\n", ans);
    return 0;
}
